package com.activity;

import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.activity.bean.JsonBean;
import com.activity.bean.SysTemBean;
import com.activity.bean.UserBean;

import com.api.param.UpdateUserParam;
import com.api.viewModel.LoginVM;
import com.baoyz.actionsheet.ActionSheet;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.donkingliang.groupedadapter.adapter.GroupedRecyclerViewAdapter;
import com.donkingliang.groupedadapter.holder.BaseViewHolder;
import com.example.apple.ddhr_new.R;
import com.example.apple.ddhr_new.activity.widget.Dialog;
import com.example.apple.ddhr_new.adapter.SystemAdapter;
import com.example.apple.ddhr_new.utils.ActivityUtil;
import com.example.apple.ddhr_new.utils.ImageViewUtil;
import com.example.lzbase.BaseViewModelActivity;
import com.google.gson.Gson;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.apache.commons.lang3.StringUtils;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import event.MessageEvent;

public class PersonInfoActivity extends BaseViewModelActivity<LoginVM> {

    @BindView(R.id.tv_brief)
    TextView tv_brief;
    @BindView(R.id.iv_beijing)
    ImageView ivBeijing;
    @BindView(R.id.iv_icon)
    ImageView ivIcon;
    @BindView(R.id.r_bg)
    RelativeLayout rBg;
    @BindView(R.id.nav_back)
    ImageButton navBack;
    @BindView(R.id.nav_title)
    TextView navTitle;
    @BindView(R.id.nav_right)
    ImageButton navRight;
    @BindView(R.id.recycle_view)
    RecyclerView recycleView;

    private SystemAdapter adapter;
    private int selectIndex;
    private List<JsonBean> options1Items = new ArrayList<>();
    private ArrayList<ArrayList<String>> options2Items = new ArrayList<>();
    private ArrayList<ArrayList<ArrayList<String>>> options3Items = new ArrayList<>();
    private boolean isBG;
    private String imgurl;

    @Override
    protected int titleText() {
        return R.string.shezhi_geren_ziliao;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_person_info;
    }


    @Override
    protected void created(@Nullable Bundle savedInstanceState) {
        super.created(savedInstanceState);


        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) rBg.getLayoutParams();
        Window window = getWindow();
        WindowManager m = getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        params.height = (int) (d.getWidth() * 3.0 / 5.0);
        rBg.setLayoutParams(params);
        SystemAdapter systemAdapter = new SystemAdapter(this, SystemAdapter.RecycleViewType.GROUP);

        adapter = systemAdapter;

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) {

            @Override

            public boolean canScrollVertically() {

                return false;

            }

        };

        recycleView.setLayoutManager(linearLayoutManager);
        recycleView.setAdapter(adapter);



        adapter.checkedChangeListener = new SystemAdapter.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(int groupPosition, int childPosition, boolean isChecked) {

            }

            @Override
            public void onSubTitleClick(int groupPosition, int childPosition) {


                if(childPosition==1){
                    Bundle bundle = new Bundle();
                    bundle.putString("title", "修改职业");
                    bundle.putString("hint", "请输入职业");
                    bundle.putString("content", App.getInstance().getAccount().getUserrank());
                    bundle.putString("type", "4");
                    ActivityUtil.startActivity(PersonInfoActivity.this, EditActivity.class, bundle, 100);

                }else {
                    childClick(groupPosition,childPosition);
                }



            }
        };

        adapter.setOnChildClickListener(new GroupedRecyclerViewAdapter.OnChildClickListener() {
            @Override
            public void onChildClick(GroupedRecyclerViewAdapter adapter, BaseViewHolder holder, int groupPosition, int childPosition) {

               childClick(groupPosition,childPosition);
            }
        });


        viewModel.updateUserinfo.observe(this, res -> {


            freshData();

        });

        freshData();
        new Thread() {
            @Override
            public void run() {
                initJsonData();
            }
        }.start();


    }

    private void childClick(int groupPosition, int childPosition) {
        selectIndex = childPosition;
        SysTemBean sysTemBean = (SysTemBean) ((List) adapter.getData().get(groupPosition)).get(childPosition);

        if (childPosition == 10) {
            Calendar min = Calendar.getInstance();
            Calendar max = Calendar.getInstance();
            Calendar selectDate = Calendar.getInstance();
            min.set(1900, 1, 1);
            max.setTime(new Date());

            TimePickerView builder = Dialog.popTime(PersonInfoActivity.this, min, max, new OnTimeSelectListener() {
                @Override
                public void onTimeSelect(Date date, View v) {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    String dateString = simpleDateFormat.format(date);

                    UpdateUserParam param = getParam();

                    param.userbirthday = dateString;

                    addSubscription(viewModel.updateUserinfo(param));
//                            dataBean.content = simpleDateFormat.format(date);
//                            countEditAdapter.notifyChildChanged(groupPosition,childPosition);
                }
            });

            // 如果不设置的话，默认是系统时间*/


            if (sysTemBean.subTitle == null) {
                selectDate.setTime(new Date());
            } else {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                try {
                    selectDate.setTime(simpleDateFormat.parse(sysTemBean.subTitle));
                } catch (ParseException e) {

                }
            }
            builder.setDate(selectDate);
            builder.show();
        } else if (childPosition ==9) {
            ArrayList<String> item1 = new ArrayList<>();

            item1.add("男");
            item1.add("女");
            OptionsPickerView optionsPickerView = Dialog.popWheel(PersonInfoActivity.this, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {

                    UpdateUserParam param = getParam();

                    if (options1 == 0) {
                        param.usersex = "1";
                    } else {
                        param.usersex = "2";
                    }


                    addSubscription(viewModel.updateUserinfo(param));


                }
            });
            int index = 0;
            if (item1.contains(sysTemBean.subTitle)) {
                index = item1.indexOf(sysTemBean.subTitle);
            } else {

            }


            optionsPickerView.setSelectOptions(index);
            optionsPickerView.setPicker(item1);
            optionsPickerView.show();
        } else if (childPosition == 7) {

            OptionsPickerView optionsPickerView = Dialog.popWheel(PersonInfoActivity.this, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {

                    UpdateUserParam param = getParam();
                    String opt1tx = options1Items.size() > 0 ?
                            options1Items.get(options1).getPickerViewText() : "";

                    String opt2tx = options2Items.size() > 0
                            && options2Items.get(options1).size() > 0 ?
                            options2Items.get(options1).get(options2) : "";
                    param.userprovince = opt1tx;
                    param.usercity = opt2tx;


                    addSubscription(viewModel.updateUserinfo(param));


                }
            });


            optionsPickerView.setTitleText("城市选择");
            optionsPickerView.setPicker(options1Items, options2Items);//三级选择器
            optionsPickerView.show();


        } else if (childPosition == 1) {


            Bundle bundle = new Bundle();
            bundle.putString("title", "修改昵称");
            bundle.putString("hint", "请输入昵称");
            bundle.putString("content", App.getInstance().getAccount().getUsernickname());
            bundle.putString("type", "0");
            ActivityUtil.startActivity(PersonInfoActivity.this, EditActivity.class, bundle, 100);

        } else if (childPosition == 2) {
            ArrayList<String> item1 = new ArrayList<>();
            item1.add("无");
            item1.add("理发师");
            item1.add("美容师");
            item1.add("美甲师");
            item1.add("美睫师");
            item1.add("造型师");
            item1.add("纹绣师");
            item1.add("化妆师");

            OptionsPickerView optionsPickerView = Dialog.popWheel(PersonInfoActivity.this, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {

                    UpdateUserParam param = getParam();

                    param.userrank = item1.get(options1);


                    addSubscription(viewModel.updateUserinfo(param));


                }
            });
            int index = 0;
            if (item1.contains(sysTemBean.subTitle)) {
                index = item1.indexOf(sysTemBean.subTitle);
            } else {

            }


            optionsPickerView.setSelectOptions(index);
            optionsPickerView.setPicker(item1);
            optionsPickerView.show();

//                    Bundle bundle = new Bundle();
//                    bundle.putString("title", "修改职业");
//                    bundle.putString("hint", "请输入职业");
//                    bundle.putString("content", App.getInstance().getAccount().getUserrank());
//                    bundle.putString("type", "2");
//                    ActivityUtil.startActivity(PersonInfoActivity.this, EditActivity.class, bundle, 100);

        }
        else if (childPosition == 5) {


            Bundle bundle = new Bundle();
            bundle.putString("title", "修改姓名");
            bundle.putString("hint", "请输入姓名");
            bundle.putString("content", App.getInstance().getAccount().getUserrealname());
            bundle.putString("type", "2");
            ActivityUtil.startActivity(PersonInfoActivity.this, EditActivity.class, bundle, 100);

        }
        else if (childPosition == 6) {


            Bundle bundle = new Bundle();
            bundle.putString("title", "修改邮箱");
            bundle.putString("hint", "请输入邮箱");
            bundle.putString("content", App.getInstance().getAccount().getUseremail());
            bundle.putString("type", "5");
            ActivityUtil.startActivity(PersonInfoActivity.this, EditActivity.class, bundle, 100);

        }else if (childPosition == 3) {


            Bundle bundle = new Bundle();
            bundle.putString("title", "修改公司");
            bundle.putString("hint", "请输入公司名称");
            bundle.putString("content", App.getInstance().getAccount().getUsercompany());
            bundle.putString("type", "7");
            ActivityUtil.startActivity(PersonInfoActivity.this, EditActivity.class, bundle, 100);

        }
        else if (childPosition == 4) {


            Bundle bundle = new Bundle();
            bundle.putString("title", "修改电话");
            bundle.putString("hint", "请输入电话");
            bundle.putString("content", App.getInstance().getAccount().getUsertel());
            bundle.putString("type", "8");
            ActivityUtil.startActivity(PersonInfoActivity.this, EditActivity.class, bundle, 100);

        }
        else if (childPosition == 8) {


            Bundle bundle = new Bundle();
            bundle.putString("title", "详细地址");
            bundle.putString("hint", "请输入详细地址");
            bundle.putString("content", App.getInstance().getAccount().getUseraddress());
            bundle.putString("type", "6");
            ActivityUtil.startActivity(PersonInfoActivity.this, EditActivity.class, bundle, 100);

        }
        else if (childPosition == 11) {


            Bundle bundle = new Bundle();
            bundle.putString("title", "修改个人简介");
            bundle.putString("hint", "请输入个人简介");
            bundle.putString("content", App.getInstance().getAccount().getUserbrief());
            bundle.putString("type", "1");
            ActivityUtil.startActivity(PersonInfoActivity.this, EditActivity.class, bundle, 100);

        }
    }

    private void initJsonData() {//解析数据

        /**
         * 注意：assets 目录下的Json文件仅供参考，实际使用可自行替换文件
         * 关键逻辑在于循环体
         *
         * */
        String JsonData = new GetJsonDataUtil().getJson(this, "province.json");//获取assets目录下的json文件数据

        ArrayList<JsonBean> jsonBean = parseData(JsonData);//用Gson 转成实体

        /**
         * 添加省份数据
         *
         * 注意：如果是添加的JavaBean实体，则实体类需要实现 IPickerViewData 接口，
         * PickerView会通过getPickerViewText方法获取字符串显示出来。
         */
        options1Items = jsonBean;

        for (int i = 0; i < jsonBean.size(); i++) {//遍历省份
            ArrayList<String> cityList = new ArrayList<>();//该省的城市列表（第二级）
            ArrayList<ArrayList<String>> province_AreaList = new ArrayList<>();//该省的所有地区列表（第三极）

            for (int c = 0; c < jsonBean.get(i).getCityList().size(); c++) {//遍历该省份的所有城市
                String cityName = jsonBean.get(i).getCityList().get(c).getName();
                cityList.add(cityName);//添加城市
                ArrayList<String> city_AreaList = new ArrayList<>();//该城市的所有地区列表

                //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                /*if (jsonBean.get(i).getCityList().get(c).getArea() == null
                        || jsonBean.get(i).getCityList().get(c).getArea().size() == 0) {
                    city_AreaList.add("");
                } else {
                    city_AreaList.addAll(jsonBean.get(i).getCityList().get(c).getArea());
                }*/
                city_AreaList.addAll(jsonBean.get(i).getCityList().get(c).getArea());
                province_AreaList.add(city_AreaList);//添加该省所有地区数据
            }

            /**
             * 添加城市数据
             */
            options2Items.add(cityList);

            /**
             * 添加地区数据
             */
            options3Items.add(province_AreaList);
        }


    }

    public void updata(UpdateUserParam param) {

        UserBean userBean = App.getInstance().getAccount();

        userBean.setUsericon(param.usericon);
        userBean.setUsernickname(param.usernickname);
        userBean.setUserbirthday(param.userbirthday);
        userBean.setUserprovince(param.userprovince);

        userBean.setUsercity(param.usercity);
        userBean.setUsersex(param.usersex);
        userBean.setUserbrief(param.userbrief);
        App.getInstance().setAccount(userBean);


    }

    public ArrayList<JsonBean> parseData(String result) {//Gson 解析
        ArrayList<JsonBean> detail = new ArrayList<>();
        try {
            JSONArray data = new JSONArray(result);
            Gson gson = new Gson();
            for (int i = 0; i < data.length(); i++) {
                JsonBean entity = gson.fromJson(data.optJSONObject(i).toString(), JsonBean.class);
                detail.add(entity);
            }
        } catch (Exception e) {
            e.printStackTrace();

        }
        return detail;
    }

    public void freshData() {
        adapter.getData().clear();
        ArrayList data1 = new ArrayList();

        SysTemBean user = new SysTemBean("用户名", SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        user.subTitle = App.getInstance().getAccount().getUsername();
        data1.add(user);
        SysTemBean service = new SysTemBean(getString(R.string.nick), SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        service.subTitle = App.getInstance().getAccount().getUsernickname();
        data1.add(service);
        SysTemBean zhiye = new SysTemBean("职业", SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        zhiye.subTitle = App.getInstance().getAccount().getUserrank();
        data1.add(zhiye);

        SysTemBean company = new SysTemBean("公司", SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        company.subTitle = App.getInstance().getAccount().getUsercompany();
        data1.add(company);
        SysTemBean sys = new SysTemBean("电话", SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        sys.subTitle = App.getInstance().getAccount().getUsertel();

        data1.add(sys);

        SysTemBean service1 = new SysTemBean("姓名", SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        service1.subTitle = App.getInstance().getAccount().getUserrealname();
        data1.add(service1);

        SysTemBean youxiang = new SysTemBean("邮箱", SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        youxiang.subTitle = App.getInstance().getAccount().getUseremail();
        data1.add(youxiang);



        SysTemBean help = new SysTemBean(getString(R.string.diqu), SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        help.subTitle = App.getInstance().getAccount().getUserprovince() + App.getInstance().getAccount().getUsercity();
        data1.add(help);

        SysTemBean dizhi = new SysTemBean("详细地址", SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        dizhi.subTitle = App.getInstance().getAccount().getUseraddress();
        data1.add(dizhi);
        SysTemBean sex = new SysTemBean(getString(R.string.xingbie), SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        if (App.getInstance().getAccount().getUsersex().equals("0")) {

        } else {
            sex.subTitle = App.getInstance().getAccount().getUsersex().equals("2") ? "女" : "男";
        }

        data1.add(sex);

        SysTemBean aboutUs = new SysTemBean(getString(R.string.chusheng_riqi), SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        aboutUs.subTitle = App.getInstance().getAccount().getUserbirthday();
        data1.add(aboutUs);

        SysTemBean brief = new SysTemBean(getString(R.string.geren_jianjie), SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        brief.subTitle ="";


        data1.add(brief);

        adapter.getData().add(data1);
        adapter.notifyDataChanged();

        if (StringUtils.isEmpty(App.getInstance().getAccount().getUsericon())) {

        } else {
            ImageViewUtil.loadCircleImage(App.getInstance().getAccount().getUsericon(), ivIcon, this);
        }
        if (StringUtils.isEmpty(App.getInstance().getAccount().getUserbackground())) {
            ivBeijing.setImageResource(R.drawable.iconbg);

        } else {
            ImageViewUtil.loadImage(App.getInstance().getAccount().getUserbackground(), ivBeijing, this,R.drawable.iconbg);
        }
        tv_brief.setText( App.getInstance().getAccount().getUserbrief());


    }


    public static UpdateUserParam getParam() {
        UpdateUserParam param = new UpdateUserParam();
        UserBean userBean = App.getInstance().getAccount();
        param.usericon = userBean.getUsericon();
        param.usernickname = userBean.getUsernickname();
        param.userbirthday = userBean.getUserbirthday();
        param.userprovince = userBean.getUserprovince();
        param.userrealname = userBean.getUserrealname();
        param.usercity = userBean.getUsercity();
        param.usersex = userBean.getUsersex();
        param.userbrief = userBean.getUserbrief();
        param.userfacecertificated = userBean.getUserfacecertificated();
        param.userbackground = userBean.getUserbackground();
        param.userrank = userBean.getUserrank();
        param.useremail = userBean.getUseremail();
        param.useraddress = userBean.getUseraddress();
        param.usercompany = userBean.getUsercompany();
        param.usertel = userBean.getUsertel();
        return param;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 1000 && requestCode == 100) {
            if (data.getStringExtra("type").equals("0")) {
                //修改昵称

                UpdateUserParam param = getParam();

                param.usernickname = data.getStringExtra("data");


                addSubscription(viewModel.updateUserinfo(param));

            } else if (data.getStringExtra("type").equals("1")) {
                //修改昵称

                UpdateUserParam param = getParam();

                param.userbrief = data.getStringExtra("data");


                addSubscription(viewModel.updateUserinfo(param));

            }
            else if (data.getStringExtra("type").equals("2")) {


                UpdateUserParam param = getParam();

                param.userrealname = data.getStringExtra("data");


                addSubscription(viewModel.updateUserinfo(param));

            }
            else if (data.getStringExtra("type").equals("4")) {


                UpdateUserParam param = getParam();

                param.userrank = data.getStringExtra("data");


                addSubscription(viewModel.updateUserinfo(param));

            }
            else if (data.getStringExtra("type").equals("5")) {


                UpdateUserParam param = getParam();

                param.useremail = data.getStringExtra("data");


                addSubscription(viewModel.updateUserinfo(param));

            }
            else if (data.getStringExtra("type").equals("6")) {


                UpdateUserParam param = getParam();

                param.useraddress = data.getStringExtra("data");


                addSubscription(viewModel.updateUserinfo(param));

            } else if (data.getStringExtra("type").equals("7")) {


                UpdateUserParam param = getParam();

                param.usercompany = data.getStringExtra("data");


                addSubscription(viewModel.updateUserinfo(param));

            }else if (data.getStringExtra("type").equals("8")) {


                UpdateUserParam param = getParam();

                param.usertel = data.getStringExtra("data");


                addSubscription(viewModel.updateUserinfo(param));

            }
        }


        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case PictureConfig.CHOOSE_REQUEST:
                    // 图片、视频、音频选择结果回调
                    List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);


                    ArrayList<String> arrayList = new ArrayList<>();
                    for (int i = 0; i < selectList.size(); i++) {
                        LocalMedia media = selectList.get(i);
                        String path = media.getCompressPath();

                        arrayList.add(path);

                    }

                    viewModel.uplaodImages(arrayList, new LoginVM.ImageResult() {
                        @Override
                        public void result(ArrayList<String> result,ArrayList<String> origin) {

                            if(result.size()==0)
                                return;
                            imgurl = result.get(0);

                            UpdateUserParam param = new UpdateUserParam();
                            UserBean userBean = App.getInstance().getAccount();
                            if(isBG){
                                param.userbackground  =imgurl;
                                param.usericon =userBean.getUsericon();
                            }else
                            {
                                param.usericon =imgurl;
                                param.userbackground  =userBean.getUserbackground();
                            }
                            param.userprovince = userBean.getUserprovince();
                            param.usernickname  =userBean.getUsernickname();
                            param.userbirthday  =userBean.getUserbirthday();
                            param.useraddress  =userBean.getUseraddress();
                            param.usercity  =userBean.getUsercity();
                            param.usersex  =userBean.getUsersex();
                            param.userrealname = userBean.getUserrealname();
                            param.userbrief  =userBean.getUserbrief();
                            param.userrank = userBean.getUserrank();
                            param.userfacecertificated = userBean.getUserfacecertificated();
                            param.usercompany = userBean.getUsercompany();
                            param.usertel = userBean.getUsertel();
                            param.useremail = userBean.getUseremail();
                            addSubscription(viewModel.updateUserinfo(param));
                        }
                    },"usericon");
//                    picture.reload();

                    // 例如 LocalMedia 里面返回三种path
                    // 1.media.getPath(); 为原图path
                    // 2.media.getCutPath();为裁剪后path，需判断media.isCut();是否为true  注意：音视频除外
                    // 3.media.getCompressPath();为压缩后path，需判断media.isCompressed();是否为true  注意：音视频除外
                    // 如果裁剪并压缩了，以取压缩路径为准，因为是先裁剪后压缩的

                    break;
            }
        }
    }

    @OnClick(R.id.l_brief)
    public void briefClicked() {


        Bundle bundle = new Bundle();
        bundle.putString("title", "修改个人简介");
        bundle.putString("hint", "请输入个人简介");
        bundle.putString("content", App.getInstance().getAccount().getUserbrief());
        bundle.putString("type", "1");
        ActivityUtil.startActivity(PersonInfoActivity.this, EditActivity.class, bundle, 100);
    }
    @OnClick(R.id.tv_set)
    public void onViewClicked() {

        isBG = true;
        getphoto();
    }
    @OnClick(R.id.tv_reset)
    public void resetClicked() {

        isBG = true;

        UpdateUserParam param = new UpdateUserParam();
        UserBean userBean = App.getInstance().getAccount();

            param.userbackground  ="";
            param.usericon =userBean.getUsericon();


        param.usernickname  =userBean.getUsernickname();
        param.userbirthday  =userBean.getUserbirthday();
        param.userprovince  =userBean.getUserprovince();
        param.usercity  =userBean.getUsercity();
        param.usersex  =userBean.getUsersex();
        param.userrealname = userBean.getUserrealname();
        param.userbrief  =userBean.getUserbrief();
        param.userrank = userBean.getUserrank();
        param.userfacecertificated = userBean.getUserfacecertificated();
        param.usercompany = userBean.getUsercompany();
        param.usertel = userBean.getUsertel();
        addSubscription(viewModel.updateUserinfo(param));

    }
    private void getphoto() {
        ActionSheet.createBuilder(PersonInfoActivity.this, getSupportFragmentManager())
                .setCancelButtonTitle(getString(R.string.cacel))
                .setOtherButtonTitles(getString(R.string.camera), getString(R.string.take_photo))
                .setCancelableOnTouchOutside(true)
                .setListener(new ActionSheet.ActionSheetListener() {
                    @Override
                    public void onDismiss(ActionSheet actionSheet, boolean isCancel) {

                    }

                    @Override
                    public void onOtherButtonClick(ActionSheet actionSheet, int index) {

                        if (index == 0) {
                            PictureSelector.create(PersonInfoActivity.this)
                                    .openCamera(PictureMimeType.ofImage())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()

                                    .maxSelectNum(1)// 最大图片选择数量 int
                                    .imageSpanCount(4)// 每行显示个数 int
                                    .selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
                                    .previewImage(true)// 是否可预览图片 true or false
                                    .previewVideo(true)// 是否可预览视频 true or false
                                    .enablePreviewAudio(true) // 是否可播放音频 true or false
                                    .isCamera(true)// 是否显示拍照按钮 true or false
                                    .imageFormat(PictureMimeType.PNG)// 拍照保存图片格式后缀,默认jpeg
                                    .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
                                    .sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效
                                    .enableCrop(isBG?false:true)
                                    .showCropGrid(false)
                                    .withAspectRatio(1,1)
                                    .compress(true)// 是否压缩 true or false
                                    .isGif(false)// 是否显示gif图片 true or false
                                    .openClickSound(false)// 是否开启点击声音 true or false
                                    .previewEggs(true)// 预览图片时 是否增强左右滑动图片体验(图片滑动一半即可看到上一张是否选中) true or false
                                    .minimumCompressSize(100)// 小于100kb的图片不压缩
                                    .synOrAsy(true)//同步true或异步false 压缩 默认同步
                                    .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
                        } else {
                            PictureSelector.create(PersonInfoActivity.this)
                                    .openGallery(PictureMimeType.ofImage())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()

                                    .maxSelectNum(1)// 最大图片选择数量 int
                                    .imageSpanCount(4)// 每行显示个数 int
                                    .selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
                                    .previewImage(true)// 是否可预览图片 true or false
                                    .previewVideo(true)// 是否可预览视频 true or false
                                    .enablePreviewAudio(true) // 是否可播放音频 true or false
                                    .isCamera(true)// 是否显示拍照按钮 true or false
                                    .imageFormat(PictureMimeType.PNG)// 拍照保存图片格式后缀,默认jpeg
                                    .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
                                    .sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效
                                    .enableCrop(isBG?false:true)
                                    .showCropGrid(false)
                                     .withAspectRatio(1,1)
                                    .compress(true)// 是否压缩 true or false
                                    .isGif(false)// 是否显示gif图片 true or false
                                    .openClickSound(false)// 是否开启点击声音 true or false
                                    .previewEggs(true)// 预览图片时 是否增强左右滑动图片体验(图片滑动一半即可看到上一张是否选中) true or false
                                    .minimumCompressSize(100)// 小于100kb的图片不压缩
                                    .synOrAsy(true)//同步true或异步false 压缩 默认同步
                                    .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
                        }
                    }
                }).show();
    }


    @OnClick(R.id.iv_icon)
    public void onIconClicked() {
        isBG = false;
        getphoto();
    }


}
